//
// misc_UNIX.cpp
// libprotea
// Tools Library for the Protea Project / Miscellaneous functionalities, specific to UNIX
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

#include "../OS_defines.h"
#ifdef OS_UNIX

#include "../defines.h"
#include <ctype.h>
#include "misc.h"
#include "../defns.h"
using namespace ProteaApp1;

int XCStrCaseCompare( const char *string1, const char *string2 )
{
	return strcasecmp( string1, string2 );	// BSD 4.3 & HP-UX 11.0
};

const char* XCGetUserName() {
	passwd* info = getpwuid( getuid() );
	if (info)
		return info->pw_name;
	else
		return NULL;
};

const char* XCGetSystemTime()
{
	static char strtime[ 13 ];
	time_t ltime;
	tm *newtime;

	time( &ltime );
	newtime = localtime( &ltime );

	sprintf( strtime, "%2.2d:%2.2d:%2.2d", newtime->tm_hour, newtime->tm_min, newtime->tm_sec );

	return strtime;
};

void ToolsRaiseOSError( long errnum, const char* file, int line, XCAppInterface* app, const void* parm ) {
	char temp[ 4096 ];
	int start;

	start = sprintf( temp, "[%ld] ", errnum );

	strcpy( temp+start, strerror( errno ) );

//	cout << "*** OS ERROR *** " << file << " line: " << line << "  " << temp << endl;
	if (parm)
		throw XCToolsError( ERR_OS_ERROR_PARM, line, app, 0, 0, 2, temp, parm );
	else
		throw XCToolsError( ERR_OS_ERROR, line, app, 0, 0, 1, temp );
};

#endif // OS_UNIX
